//concommand.Add("+aradio", showPanel)
aaronsmenuversion = "Aaron's Radio"
aaronsmenushortversion = "A-Radio"
local firstruncheck = 0
local pan
local function showPanel()
	if firstruncheck == 0 then
		panel = vgui.Create( "DFrame" )
		panel:SetPos( 100, 60)
		panel:SetSize(800, 600)
		panel:SetTitle( aaronsmenuversion )
		panel:SetVisible( true )
		panel:SetDraggable( true )
		panel:ShowCloseButton( false )
		panel:SetSizable(true)
		panel:MakePopup()
		pan = panel
		local w = panel:GetWide()
		local h =  panel:GetTall()
		local closebutton = vgui.Create( "DImageButton", panel ) 
		closebutton:SetPos( 780, 5 )
		closebutton:SetImage( "silkicons/cross.vtf" )
		closebutton:SizeToContents()
		closebutton.DoClick = function()
			LocalPlayer():ConCommand("-aradio")
		end
		local PropertySheet = vgui.Create( "DPropertySheet" )
		PropertySheet:SetParent( panel )
		PropertySheet:SetPos( 5, 30 )
		PropertySheet:SetSize( w-10, h-35 ) 
		--------------------------Begin Radio Tab----------------------------------
		radiourl = [[<html>
					<body><font size="1" face="Verdana"><center>
					<b>Welcome</b><br>
					This Is Aarons GarrysMod Radio<br>
					You can load your custom url's by pressing the "load custom url" button below <br>
					Make sure you dont put the http:// or www. tho or else it wont work<br>
					Or you can load one of our fine selection of stations above :D <br>
					<font size="1" face="Verdana"></center>
					</body>
					</html>
					]]
		local RADIO = vgui.Create( "DPanel", PropertySheet )
		RADIO:SetSize( w-20, h-45 )
		RADIO.Paint = function()
			surface.SetDrawColor( 0, 0, 0, 0 )
			surface.DrawRect( 0, 0, RADIO:GetWide(), RADIO:GetTall() )
		end
		radiolist = vgui.Create("DListView")
		radiolist:SetParent(RADIO)
		radiolist:SetPos(1, 1)
		radiolist:SetSize(775, 430)
		radiolist:SetMultiSelect(false)
		radiolist:SetSortable(true)
		local lstRadioTitle = radiolist:AddColumn("Title")
		local lstRadioURL = radiolist:AddColumn("URL")
		local lstRadioGenre = radiolist:AddColumn("Genre")
		local lstRadioType = radiolist:AddColumn("Type")
		radiolist:SortByColumn( 1 )
		lstRadioTitle:SetWide( 100 )
		lstRadioURL:SetWide( 300 )
		lstRadioGenre:SetWide( 15 )
		lstRadioType:SetWide( 1 )
		radiopage = vgui.Create( "HTML" , RADIO);
		radiopage:SetPos(0,445);
		radiopage:SetSize(775,255);
		radiopage:SetVisible(true);
		radiopage:SetHTML( radiourl );
		radiopage:Refresh(true);
		radiolist.OnRowSelected = function()
			radioselect = DermaMenu()
			radioselect:AddOption("Load This For Me Please", function()
				panel:SetTitle( aaronsmenushortversion.." - Currently Listining To: Title: "..radiosongTitle..
				"  URL: "..radiosongURL.."  Genre: "..radiosongGenre )
				radiourl = [[<center>
							<OBJECT ID="MediaPlayer" WIDTH="750" HEIGHT="44" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
							STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">
							<PARAM NAME="FileName" VALUE="http://]]..radiosongURL..[[">
							<PARAM name="autostart" VALUE="true">
							<PARAM name="ShowControls" VALUE="true">
							<param name="ShowStatusBar" value="false">
							<PARAM name="ShowDisplay" VALUE="false">
							</OBJECT>
							</center>]]
				radiopage:SetHTML( radiourl );
				print("\n\nCurrently Selected Song: \nTitle: "..radiosongTitle.."\nURL: "..radiosongURL.."\nGenre: "..radiosongGenre.."\nType: "..radiosongType.."\n\n")
			end )
			radioselect:Open()
		radiosongTitle = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(1)
		radiosongURL = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(2)
		radiosongGenre = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(3)
		radiosongType = radiolist:GetLine(radiolist:GetSelectedLine()):GetValue(4)
		end
		radiostop = vgui.Create( "DButton", RADIO )
		radiostop:SetParent( RADIO )
		radiostop:SetSize(RADIO:GetWide()-500, 15)
		radiostop:SetPos( 490,432 )
		radiostop:SetText( "Refresh The Radio" )
		radiostop.DoClick = function( button )
			LocalPlayer():ConCommand("aradio_reload")
		end
		radiostop = vgui.Create( "DButton", RADIO )
		radiostop:SetParent( RADIO )
		radiostop:SetSize(RADIO:GetWide()-532, 15)
		radiostop:SetPos( 248,432 )
		radiostop:SetText( "Turn Off The Radio" )
		radiostop.DoClick = function( button )
			radiourl = [[<center>Radio Stopped</center>]]
			radiopage:SetHTML( radiourl );
			panel:SetTitle( aaronsmenuversion )
		end
		radioload = vgui.Create( "DButton", RADIO )
		radioload:SetParent( RADIO )
		radioload:SetSize(RADIO:GetWide()-532, 15)
		radioload:SetPos( 1,432 )
		radioload:SetText( "Load Custom URL" )
		radioload.DoClick = function( button )
			local customradio = vgui.Create( "DFrame" )
			customradio:SetPos( 250,250 )
			customradio:SetSize( 500, 50 )
			customradio:SetTitle( "URL Link: (dont put the http:// or www. tho)" )
			customradio:ShowCloseButton( true )
			customradio:SetVisible( true )
			customradio:MakePopup()
			local customradiotext = vgui.Create( "DTextEntry", customradio )
			customradiotext:SetPos( 20,27 )
			customradiotext:SetTall( 20 )
			customradiotext:SetWide( 450 )
			customradiotext:SetEnterAllowed( true )
			customradiotext.OnEnter = function()
				customradiourl = customradiotext:GetValue()
				radiourl = [[<center>
							<OBJECT ID="MediaPlayer" WIDTH="750" HEIGHT="44" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
							STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">
							<PARAM NAME="FileName" VALUE="http://]]..customradiourl..[[">
							<PARAM name="autostart" VALUE="true">
							<PARAM name="ShowControls" VALUE="true">
							<param name="ShowStatusBar" value="false">
							<PARAM name="ShowDisplay" VALUE="false">
							</OBJECT>
							</center>]]
				radiopage:SetHTML( radiourl );
				panel:SetTitle( aaronsmenushortversion.." - Currently Listining To: "..customradiourl)
				--print("Currently Selected Song: "..customradiourl)
				customradio:SetVisible( false )
				end
			end
		function reloadAaronsRadio()
		radiolist:Clear()
		//table.Empty(MusicList)
		//table.Empty(TempT)
		function FetchList ( SiteArgs )
			MusicList = {};
			for _, Line in pairs(string.Explode("\n", SiteArgs)) do
			if string.len(Line) > 5 then
				Info = string.Explode("\t", Line);
				TempT = {};
				TempT.Title = Info[1];
				TempT.URL = Info[2];
				TempT.Genre = Info[3];
				TempT.Type = Info[4];
				table.insert(MusicList, TempT)
				end
			end
		for k, v in pairs(MusicList) do
			radiolist:AddLine(v.Title,v.URL,v.Genre,v.Type)
		end
		end
		http.Get('http://amic3r.googlecode.com/svn/trunk/radio2.html', '', FetchList);
		end
		----------------------End Radio Tab--------------------------
		----------------------Begin Pulsar Radio Tab--------------------------
		pulradiourl = [[]]
		
		local PULRADIO = vgui.Create( "DPanel", PropertySheet )
		PULRADIO:SetSize( w-20, h-45 )
		PULRADIO.Paint = function()
			surface.SetDrawColor( 0, 0, 0, 0 )
			surface.DrawRect( 0, 0, PULRADIO:GetWide(), PULRADIO:GetTall() )
		end
		pulradiolist = vgui.Create("DListView")
		pulradiolist:SetParent(PULRADIO)
		pulradiolist:SetPos(1, 1)
		pulradiolist:SetSize(775, 520)
		pulradiolist:SetMultiSelect(false)
		pulradiolist:SetSortable(true)
		local lstPulArtist = pulradiolist:AddColumn("Artist")
		local lstPulTitle = pulradiolist:AddColumn("Title")
		local lstPulID = pulradiolist:AddColumn("Pulsar ID")
		pulradiolist:SortByColumn( 1 )
		lstPulArtist:SetWide( 300 )
		lstPulTitle:SetWide( 300 )
		lstPulID:SetWide( 1 )
		pulradiopage = vgui.Create( "HTML" , PULRADIO);
		pulradiopage:SetPos(0,600);
		pulradiopage:SetSize(775,0);
		pulradiopage:SetVisible(true);
		pulradiopage:SetHTML( radiourl );
		pulradiopage:Refresh(true);
		pulradiolist.OnRowSelected = function()
			pulradioselect = DermaMenu()
			pulradioselect:AddOption("Load This For Me Please", function()
				panel:SetTitle( aaronsmenushortversion.." - Currently Listining To:  Title: "..pulradiosongTitle..
				"  Artist: "..pulradiosongArtist)
				pulradiourl = [[<iframe src ="http://www.pulsareffect.com/jukebox/fetch.php?id=]]..pulradiosongID..[[" width="100%" height="%100"></iframe>]]
				pulradiopage:SetHTML( pulradiourl );
				myradiotype = "pulsar"
				print("\n\nCurrently Selected Song: \nTitle: "..pulradiosongTitle.."\nArtist: "..pulradiosongArtist.."\n\n")
			end )
			pulradioselect:Open()
		pulradiosongID = pulradiolist:GetLine(pulradiolist:GetSelectedLine()):GetValue(3)
		pulradiosongArtist = pulradiolist:GetLine(pulradiolist:GetSelectedLine()):GetValue(1)
		pulradiosongTitle = pulradiolist:GetLine(pulradiolist:GetSelectedLine()):GetValue(2)
		end
		pulradiostop = vgui.Create( "DButton", PULRADIO )
		pulradiostop:SetParent( PULRADIO )
		pulradiostop:SetSize(390, 15)
		pulradiostop:SetPos( 370,520 )
		pulradiostop:SetText( "Stop This Song" )
		pulradiostop.DoClick = function( button )
			pulradiourl = [[<center>Radio Stopped</center>]]
			pulradiopage:SetHTML( pulradiourl );
			panel:SetTitle( aaronsmenuversion )
		end
		pulradioload = vgui.Create( "DButton", PULRADIO )
		pulradioload:SetParent( PULRADIO )
		pulradioload:SetSize(370, 15)
		pulradioload:SetPos( 1,520 )
		pulradioload:SetText( "Load Custom URL" )
		pulradioload.DoClick = function( button )
			local pulcustomradio = vgui.Create( "DFrame" )
			pulcustomradio:SetPos( 250,250 )
			pulcustomradio:SetSize( 500, 50 )
			pulcustomradio:SetTitle( "URL Link: (dont put the http:// or www. tho)" )
			pulcustomradio:ShowCloseButton( true )
			pulcustomradio:SetVisible( true )
			pulcustomradio:MakePopup()
			local pulcustomradiotext = vgui.Create( "DTextEntry", pulcustomradio )
			pulcustomradiotext:SetPos( 20,27 )
			pulcustomradiotext:SetTall( 20 )
			pulcustomradiotext:SetWide( 450 )
			pulcustomradiotext:SetEnterAllowed( true )
			pulcustomradiotext.OnEnter = function()
				pulcustomradiourl = pulcustomradiotext:GetValue()
				pulradiourl = [[<iframe src ="http://]]..pulcustomradiourl..[[" width="100%" height="%100"></iframe>]]
				pulradiopage:SetHTML( pulradiourl );
				panel:SetTitle( aaronsmenushortversion.." - Currently Listining To: "..pulcustomradiourl)
				print("\n\nCurrently Selected Song: "..pulcustomradiourl.."\n\n")
				pulcustomradio:SetVisible( false )
				end
			end
		pulradiostop = vgui.Create( "DButton", PULRADIO )
		pulradiostop:SetParent( PULRADIO )
		pulradiostop:SetSize(16, 15)
		pulradiostop:SetPos( 760,520 )
		pulradiostop:SetText( " " )
		pulradiostop.DoClick = function( button )
			print("\nLUL YOU FOUND DA SEKRET BTN    :D")
		end
		function pulFetchList ( pulSiteArgs )
			pulMusicList = {};
			for _, Line in pairs(string.Explode("\n", pulSiteArgs)) do
			if string.len(Line) > 5 then
				pulInfo = string.Explode("\t", Line);
				pulTempT = {};
				pulTempT.ID = pulInfo[1];
				pulTempT.Artist = pulInfo[2];
				pulTempT.Title = pulInfo[3];
				table.insert(pulMusicList, pulTempT)
				end
			end
			for k, v in pairs(pulMusicList) do
				pulradiolist:AddLine(v.Artist,v.Title,v.ID)
			end
		end
		http.Get('http://www.pulsareffect.com/jukebox/list.html', '', pulFetchList);
		----------------------End Pulsar Radio Tab--------------------------
		
		
		PropertySheet:AddSheet( "Aaron's Radio", RADIO, "gui/silkicons/sound", false, false, "Listen To Some Music" )
		PropertySheet:AddSheet( "PulsarEffect Radio", PULRADIO, "gui/silkicons/sound", false, false, "Listen To Some Music" )
		reloadAaronsRadio()
		firstruncheck = 1
	else
		panel:SetVisible(true)
		gui.EnableScreenClicker(true)
	end
end
local function hidePanel()
	if panel:IsVisible() then
		panel:SetVisible(false)
	end
	gui.EnableScreenClicker(false)
end
concommand.Add("+aradio", showPanel)
concommand.Add("-aradio", hidePanel)
concommand.Add("aradio_reload", reloadAaronsRadio)